package com.adou.d5;

public class Test4 {
    public static void main(String[] args) {
        System.out.println(enCode(1983));
    }

    public static String enCode(int num) {
        // num = 1983
        int[] nums = split(num);

        //
        for (int i = 0; i < nums.length; i++) {
            nums[i] = (nums[i]+5)%10;
        }

        // 反转
        reverse(nums);

        String data = "";
        for (int i = 0; i < nums.length; i++) {
            data += nums[i];
        }
        return data;
    }

    // 反转
    private static void reverse(int[] nums) {
        for (int i = 0; i < nums.length/2; i++) {
            int temp = nums[i];
            nums[i] = nums[nums.length - i-1];
            nums[nums.length - i-1] = temp;
        }
    }

    // 拆分数字 
    private static int[] split(int num) {
        int[] nums = new int[4];
        nums[0] = num/1000;
        nums[1] = (num/100)%10;
        nums[2] = (num/10)%10;
        nums[3] = num%10;
        return nums;
    }
}
